package com.android.geotrack.user;

import java.util.LinkedList;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;

public class UserOverlay extends ItemizedOverlay
{
	private Context context;
	private LinkedList<UserOverlayItem> overlays = new LinkedList<UserOverlayItem>();
	
	public UserOverlay(Context context, Drawable defaultMarker)
	{
		super(boundCenterBottom(defaultMarker));
		this.context = context;
	}

	@Override
	protected UserOverlayItem createItem(int i)
	{
	  return overlays.get(i);
	}

	@Override
	public int size()
	{
		return overlays.size();
	}
	
	public void addOverlay(UserOverlayItem overlay)
	{
	    overlays.add(overlay);
	    populate();
	}
	
	public void setMarker(UserOverlayItem overlay, Drawable marker)
	{
		overlay.setMarker(boundCenterBottom(marker));
	}
	
	public boolean onTap(int index) 
	{
		Intent i = new Intent(context, UserActivity.class);
		i.putExtra("user", overlays.get(index).getUser().getName());
		i.putExtra("distance", Double.toString(overlays.get(index).getUser().getDistance()));
		i.putExtra("age", Integer.toString(overlays.get(index).getUser().getAge()));
		i.putExtra("score", Double.toString(overlays.get(index).getUser().getScore()));
		i.putExtra("image", overlays.get(index).getUser().getThumbnail_large());
		i.setFlags(i.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(i);
		return false;
	}
}